/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Mobilottery.UI.Forms;

import Mobilottery.AppManager;
import Mobilottery.Constants.Consts;
import Mobilottery.Constants.Consts.Screens;
import Mobilottery.Interfaces.IAlertCommandListener;
import Mobilottery.XmlManager.OpenGamesDetails;
import javax.microedition.lcdui.*;

/**
 *
 * @author WindowsVista
 */
public class FormNewGame1 extends List implements CommandListener
{

    OpenGamesDetails _openGamesDetails;

    public FormNewGame1(Object p_obj)
    {
        super("Select a game", IMPLICIT);

        _openGamesDetails = (OpenGamesDetails) p_obj;

        super.setFitPolicy(TEXT_WRAP_ON);

        String gameName;
        int gameID;
        float gamePrice;
        Image img;

        for (int i = 0; i < _openGamesDetails.GamesNames.length; i++)
        {
            gameName = _openGamesDetails.GamesNames[i];
            gameID = _openGamesDetails.GamesIDs[i];
            gamePrice = _openGamesDetails.GamesPrices[i];


            img = Consts.UIConsts.IMAGES_NEW_GAME;
            super.append(gameName + " - " + gamePrice + "$", img);
        }

        Command cmd;
        cmd = new Command("Select", Command.OK, 0);
        this.setSelectCommand(cmd);
        this.addCommand(cmd);

        cmd = new Command("Back", Command.BACK, 0);
        this.addCommand(cmd);
        this.setCommandListener(this);
    }

    public void commandAction(Command c, Displayable d)
    {
        int cmdType = c.getCommandType();
        if (cmdType == Command.OK)
        {
            menu_Clicked();
        }
        else if (cmdType == Command.BACK)
        {
            back_Clicked();
        }
    }

    private void back_Clicked()
    {
        AppManager.goToScreen(Screens.MainMenu, null);
    }

    private void menu_Clicked()
    {
        int selectedIdx = super.getSelectedIndex();
        AppManager.goToScreen(Screens.NewGame2, new Object[]
                {
                    new Integer(selectedIdx),
                    _openGamesDetails
                });
    /*
    AppManager.setAlert(
    "Menu selected",
    "You selected: " + super.getString(selectedIdx) + "[" + selectedIdx + "]",
    null,
    "OK", null,
    new IAlertCommandListener()
    {

    public boolean onOK()
    {
    return true;
    }

    public boolean onCancel()
    {
    return true;
    }
    });
     */
    }
}

